package cn.nubia.admin.sysconfig.controller;

import cn.nubia.admin.common.springmvc.Response;
import cn.nubia.admin.sysconfig.bean.SysConfigParam;
import cn.nubia.admin.sysconfig.service.SysConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2015/6/26.
 */
@Controller
@RequestMapping(value = "/system")
public class SysConfigController {


    @Autowired
    private SysConfigService sysConfigService;

    /**
     * 查看系统参数
     *
     * @return 查看系统参数.
     */
    @ResponseBody
    @RequestMapping(value = "getConfig", method = RequestMethod.GET)
    public Response<Map<String,String>> getConfig() {
        Map<String,String> map = sysConfigService.getSystemConfig();
        return Response.getSuccessResponse(map);
    }


    @RequestMapping(value = "saveConfig", method = RequestMethod.POST)
    @ResponseBody
    public Response<Boolean> saveConfig(SysConfigParam sysConfigParam) {

//        ModelAndView model = new ModelAndView("/system/sysconfig");

        String[] params = new String[]{"webName","webCopyright","webUrl","keywords","description"};


        Map<String,String> map = new HashMap<String,String>();

        map.put(params[0],sysConfigParam.getWebName());
        map.put(params[1], sysConfigParam.getWebCopyright());
        map.put(params[2], sysConfigParam.getWebUrl());
        map.put(params[3], sysConfigParam.getKeywords());
        map.put(params[4], sysConfigParam.getDescription());

        sysConfigService.saveSysConfigMap(map);
        return Response.getSuccessResponse(true);
    }
}
